home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / PIXELWOR / CPIXELWO.H < prev    next >
Text File  |  1992-01-01  |  9KB  |  197 lines

  1. /******************************************************************************
  2.  CPixelWorld.h
  3.  
  4.     Pixel World Class, Version 1.0                        (SUPERCLASS = CBitMap)
  5.     __________________________________________________________________________
  6.     
  7.     Ñ    Description
  8.         
  9.         The CPixelWorld class is a subclass of CBitMap (THINK Class Library 1.1) 
  10.         designed to maintain a color offscreen drawing environment using the 
  11.         standard conventions of Color QuickDraw.  An offscreen color graphics 
  12.         device (GDevice) and an offscreen color graphics port (CGrafPort) are 
  13.         used to maintain this offscreen world.  This implementation supports 
  14.         standard pixel depths of 1,2,4 and 8 bits.  Pixel depths of 16 and 32 
  15.         are not supported since this implementation does not rely on 32-Bit 
  16.         QuickDraw features.  In the future, support for 16 and 32 bit pixel 
  17.         depths and the offscreen GWorlds provided by 32-Bit QuickDraw can be 
  18.         incorporated into a subclass of CPixelWorld called CGWorld.  
  19.         
  20.     Ñ    Creating a Blank Pixel World
  21.         
  22.         A blank pixel world is created by calling the initialization method 
  23.         IPixelWorld() with a pixel depth (aPixelDepth), a bounds rectangle 
  24.         (aBoundsRect), a handle to a color table (aColorTable), and NULL for 
  25.         the handle to the pixel image (aPixelImage).  You can pass any value 
  26.         for row bytes (aRowBytes) since the value will be ignored in this case.  
  27.         You should pass a color table handle (CTabHandle) in the aColorTable 
  28.         parameter.  The color table is copied and the copy is used for the 
  29.         offscreen world.  If aColorTable is NULL, then the default color table 
  30.         for the desired pixel depth will be used.  
  31.         
  32.                                 *** WARNING ***
  33.         
  34.         If you request a pixel depth of one and Color QuickDraw is not 
  35.         available, then a blank offscreen world will be created as a standard 
  36.         BitMap with a non-color graphics port (GrafPort) using the CBitMap 
  37.         superclass.  If you request a pixel depth greater than one and Color 
  38.         QuickDraw is not available, the initialization method will fail.  To 
  39.         detect initialization failure call the method WorldIsOK(), which 
  40.         returns the value of the instance variable worldIsOK.  WorldIsOK() 
  41.         will return TRUE after successful initialization, and FALSE after 
  42.         initialization failure.  
  43.         
  44.     Ñ    Creating a Pixel World with an Existing Image
  45.         
  46.         A world based on an existing color or grayscale image is created by 
  47.         calling the initialization method IPixelWorld() with the pixel depth of 
  48.         the existing image (aPixelDepth), the bounds rectangle of the existing 
  49.         image (aBoundsRect), a color table for the existing image (aColorTable), 
  50.         and a handle to the pixels for the existing image (aPixelImage).  In 
  51.         this case, you must also pass a value for the row bytes of the pixel 
  52.         image (aRowBytes).  
  53.         
  54.                                *** IMPORTANT ***
  55.         
  56.         When you create an offscreen world based on an existing pixel image, 
  57.         IT IS YOUR RESPONSIBILITY TO DISPOSE OF YOUR PIXEL IMAGE.  Although 
  58.         CPixelWorld keeps its own handle to your pixel image in the instance 
  59.         variable worldPixels, it will not dispose of the pixel image.  In 
  60.         contrast, when you create a blank world by passing NULL for the 
  61.         aPixelImage parameter, CPixelWorld creates its own pixel image and it 
  62.         will dispose of this image when the offscreen world is destroyed by 
  63.         the Dispose() instance method.  
  64.         
  65.         When you create your own pixel image for use with an offscreen world 
  66.         use a multiple of four for the row bytes of your pixel image.  The 
  67.         following formula will give a multiple of four for row bytes:  
  68.         
  69.             rowBytes = ((((long) width * pixelDepth) + 31) / 32) * 4;
  70.         
  71.         A multiple of four for row bytes will give optimal performance in calls 
  72.         to the QuickDraw function CopyBits() and its related functions.  
  73.         
  74.                                 *** WARNING ***
  75.         
  76.         When you create an offscreen world with an existing image that has a 
  77.         pixel depth greater than one, the initialization method will fail if 
  78.         Color QuickDraw is not available since there is no support for images 
  79.         with pixel depths greater than one without Color QuickDraw.  
  80.         
  81.     Ñ    Drawing to the Offscreen Pixel World
  82.         
  83.         If you need to draw directly to the offscreen world, you must bracket
  84.         all drawing with calls to BeginDrawing() and EndDrawing().  This will 
  85.         set up the offscreen GDevice and CGrafPort for drawing.  In addition, 
  86.         the LockWorld() method will be called to make sure that the pixel 
  87.         image is anchored down and will not move when you invoke any QuickDraw
  88.         routines.  LockWorld() locks the handle to the pixel image, and then 
  89.         it loads the derefernced handle into the PixMap baseAddr pointers of 
  90.         both the offscreen GDevice and the offscreen CGrafPort.  
  91.         
  92.     Ñ    Version History
  93.         
  94.         __________________________________________________________
  95.         Release Version:        1.0
  96.         Release Date:            January 1, 1992
  97.         
  98.         Implemented By:            Vincent R. Vann, Jr.
  99.                                 1901 Brickell Ave, B-410
  100.                                 Miami, Florida  33129  USA
  101.         
  102.         Compuserve Address:     76530,1242
  103.         Internet Address:        vvann@umbio.med.miami.edu
  104.                                 (129.171.65.204)
  105.         __________________________________________________________
  106.         
  107.     Ñ    License Agreement
  108.         
  109.         All portions of this source code are property of Vincent R. Vann, Jr.
  110.         I, Vincent R. Vann, Jr., grant you the right to freely distribute this 
  111.         source code and to use all or part of this source code in all software  
  112.         including commercial, freeware, shareware and private applications.  
  113.         However, all software that uses any part of or all of this source code 
  114.         must display a copyright notice indicating that either all of or 
  115.         portions of this source code are used in the software.  I also grant 
  116.         you permission to alter and make improvements to this source code, but 
  117.         only if all modifications are returned to me by whatever means are 
  118.         available, either in written or electronic form.  You must also accept 
  119.         that I retain the right to include any part of your modifications or 
  120.         all of your modifications in future releases of this source code.  The 
  121.         description and version history sections above may be ammended for 
  122.         documentation purposes.  This license agreement and the copyright 
  123.         notice below must be maintained intact and must be included with all 
  124.         distributions of this source code at all times.  
  125.         
  126.         This implementation is based in part on material copyrighted by Apple 
  127.         Computer, Inc. and Symantec Corporation.  
  128.         
  129.         Copyright ⌐ 1992 Vincent R. Vann, Jr.  All rights reserved.  
  130.         
  131.  ******************************************************************************/
  132.  
  133.  
  134. #define _H_CPixelWorld
  135.  
  136. #include "CBitMap.h"                    /* Interface for its superclass        */
  137. #include "LongCoordinates.h"
  138.  
  139. class CPixelWorld : public CBitMap {        /* Class Declaration                */
  140.  
  141. public:
  142.                             /** Instance Variables **/
  143.     
  144.     Boolean                worldIsOK;            /* TRUE if initialized successfully    */
  145.     Boolean                worldHasColor;        /* TRUE if have Color QuickDraw        */
  146.     Boolean                worldHas32BitQD;    /* TRUE if have 32-Bit QuickDraw    */
  147.     Boolean                worldOwnsPixels;    /* TRUE if world owns pixel image    */
  148.     Boolean                worldPixelsLocked;    /* TRUE if pixel image is locked    */
  149.     
  150.     short                worldDepth;            /* Pixel depth                    */
  151.     LongRect            worldBounds;        /* Bounds rectangle                */
  152.     CTabHandle            worldColors;        /* Color table handle            */
  153.     Handle                worldPixels;        /* Pixel image handle            */
  154.     GDHandle            worldDevice;        /* Offscreen GDevice handle        */
  155.     CGrafPtr            worldPort;            /* Offscreen CGrafPort pointer    */
  156.     
  157.     GDHandle            saveDevice;            /* Saved graphics device        */
  158.     
  159.                             /** Instance Methods **/
  160.     
  161.                                 /** Contruction/Destruction **/
  162.     void        IPixelWorld( short aPixelDepth, Rect *aBoundsRect, 
  163.                         CTabHandle aColorTable, Handle aPixelImage, short aRowBytes);
  164.     void        IPixelWorldBW( short aPixelDepth, Rect *aBoundsRect, 
  165.                         Handle aPixelImage, short aRowBytes);
  166.     void        IPixelWorldColor( short aPixelDepth, Rect *aBoundsRect, 
  167.                         CTabHandle aColorTable, Handle aPixelImage, short aRowBytes);
  168.     
  169.     virtual void        Dispose(void);
  170.     
  171.                                 /** Accessing **/
  172.     virtual Boolean        WorldIsOK(void);
  173.     virtual void        GetBounds(LongRect *theBounds);
  174.     virtual void        SetBoundsOrigin(short hOrigin, short vOrigin);
  175.     virtual Boolean        PixelIsBlack(LongPt *pixelPos);
  176.     virtual Boolean        GetPixelColor(LongPt *pixelPos, RGBColor *color);
  177.     virtual short        GetPixelDepth(void);
  178.     virtual short        GetRowBytes(void);
  179.     virtual Handle        GetHandleToPixels(void);
  180.     virtual Ptr            GetPointerToPixels(void);
  181.     
  182.                                 /** Activate/Deactivate/Lock **/
  183.     virtual Boolean        LockWorld(Boolean setLock);
  184.     virtual    void        ActivateWorld(void);
  185.     virtual void        DeactivateWorld(void);
  186.     
  187.                                 /** Image Copying **/
  188.     virtual void        CopyTo(LongRect *fromRect, LongRect *toRect, RgnHandle maskRgn);
  189.     virtual void        CopyFrom(LongRect *fromRect, LongRect *toRect, RgnHandle maskRgn);
  190.     
  191.                                 /** Preparing **/
  192.     virtual void        BeginDrawing(void);
  193.     virtual void        EndDrawing(void);
  194. };
  195.  
  196.  
  197.